package com.jvm.interpreter.instruction;

import com.jvm.classfile.model.CpInfo;
import com.jvm.interpreter.ExecEnv;
import com.jvm.interpreter.Frame;
import com.jvm.interpreter.Instruction;
import com.jvm.interpreter.MetaSpace;

/**
 * @program: diy_simple_jvm
 * @description: ireturn指令
 * @author: CaoYong
 * @create: 2021-07-08 10:22
 **/
public class IReturnInst implements Instruction {

    /**
     * 将操作数栈的数据作为返回值，结束对当前方法的调用
     * @param frame 栈帧
     */
    @Override
    public void eval(Frame frame) {
//        int tmp = frame.operandStack.pop();
        ExecEnv env = MetaSpace.getMainEnv();
        env.popFrame();

        Frame now = env.topFrame();
        now.pushInt(frame.popInt());
//        int tmp = frame.popInt();
//        System.out.println(tmp);

        frame.pc += offset();
    }

    static IReturnInst parse(java.io.DataInputStream dis, CpInfo[] cp) throws java.io.IOException {
        return new IReturnInst();
    }
}
